import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
from scipy.spatial import distance
from sklearn.mixture import GaussianMixture
import matplotlib.pyplot as plt
from sklearn.mixture import GaussianMixture as GMM


fs_name = ['Fwd Packet Length Mean','Fwd Packet Length Max','Packet Length Mean','Fwd Packet Length Std','Bwd Iat Min','Packet Length Std']
data = pd.read_csv("data_model.csv")
X = data[fs_name]
print(X)
scaler = StandardScaler()
X = scaler.fit_transform(X)
y = data['Label']

'''
# calculate BIC and choose the best number of n_components
n_components = np.arange(1, 150)
models = [GMM(n, covariance_type='full', random_state=0).fit(X)
          for n in n_components]
print("model complete")
plt.plot(n_components, [m.bic(X) for m in models], label='BIC')
plt.legend(loc='best')
plt.xlabel('n_components')
plt.show()
'''
	
model = GMM(62, covariance_type='full', random_state=0)
model.fit(X)
labels = pd.DataFrame(data = model.predict(X),columns = ['GMM Label'])
labels.to_csv('gmm_label.csv', index = False)


